const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const ZonnarPlugin = require('../src/plugins/index.js');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin")

module.exports = {
    mode:'production',
    // 代表上下文的执行路径。
    context: path.resolve(process.cwd()),
    entry:{
        json:['./src/zonnar.json5'],
        home: {
            import:"./src/index.js",
            filename:"home.[hash].js",
            dependOn:'json',
            chunkLoading: 'jsonp',
        },
        // root: "./src/index.js"
    },
    devtool: 'inline-source-map',
    output:{
        // publicPath:'/static/',
        sourcePrefix: '\t',
        clean:true,
        path: path.resolve(process.cwd(), './dist03'),
        scriptType: 'module',
        filename:"[name].[chunkhash:8].js",
        chunkFilename:"[name].chunk.[chunkhash:8].js"
    },
    optimization: {
        runtimeChunk: 'single'
      },
    resolve: {
        // 要解析的文件的扩展名
        extensions: [".js", ".jsx", ".json"],
    },
    module:{
        rules:[
            {
                test: /\.(js|jsx)$/,
                use:[
                    { loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env', '@babel/preset-react']
                    }
                },
                    
                ],
                include: path.resolve(process.cwd(), '/src/react'),
                exclude: path.resolve(process.cwd(), '/node_modules/')
            },
            {
                test: /\.json5$/,
                exclude: /node_modules/,
                use: [
                    'json5-loader'
                ]
            },
        ]
    },
    plugins:[
        new webpack.ProgressPlugin(),
        new CleanWebpackPlugin(),
        new HTMLWebpackPlugin({ template: './public/index.html'}),
        new CopyWebpackPlugin({
            patterns: [
                {from : path.resolve(process.cwd(), './src/module.js'), to: path.resolve(process.cwd(), './dist03/module.js'), }
            ]
        }),
        // new CompressionPlugin({
        //     include: /\.js$/,
        //   }),
        
        new ZonnarPlugin({
            outputFile: 'assets.md'
        }),

    ]
}